package com.xmb.wechat.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ScreenUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.definterface.OnEditRoleListener;

import java.util.Objects;

/**
 * @Author lijiangop
 * @CreateTime 2020/3/25 16:47
 */
public class RoleEditDialog extends Dialog {

    private WechatContactBean mineContactBean;
    private ImageView         mIvMine;
    private LinearLayout      mLlMmine;
    private int               indexOf;
    private WechatContactBean editBean;

    public RoleEditDialog(@NonNull Context context, OnEditRoleListener listener) {
        super(context, R.style.PopupDialog);
        initView(context, listener);
    }

    private void initView(Context context, OnEditRoleListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_role_edit, null, false);
        mLlMmine = view.findViewById(R.id.ll_edit);
        mLlMmine.setOnClickListener(v -> {
            if (listener != null)
                listener.onEdit(indexOf,editBean);
            dismiss();
        });
        view.findViewById(R.id.ll_replace).setOnClickListener(v -> {
            if (listener != null)
                listener.onReplace(indexOf);
            dismiss();
        });
        view.findViewById(R.id.ll_remove).setOnClickListener(v -> {
            if (listener != null)
                listener.onRemove(indexOf);
            dismiss();
        });
        mIvMine = view.findViewById(R.id.iv_mine);
        setContentView(view);
        WindowManager.LayoutParams lp = Objects.requireNonNull(getWindow()).getAttributes();
        lp.width = ScreenUtils.getScreenWidth();
        lp.dimAmount = 0.5f;
        lp.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    public void setCurrentPosition(int indexOf) {
        this.indexOf = indexOf;
    }

    public void setCurrentItem(WechatContactBean item) {
        this.editBean = item;
    }
}
